package ${package.Controller};

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import ${package.Service}.${table.serviceName};
import ${package.Entity}.${entity};

@Api(tags = "${package.ModuleName} ${table.comment!}")
@Log4j2
@Validated
@RestController
@RequestMapping(value = "/${package.ModuleName}/${table.entityPath}/", produces = "application/json;charset=UTF-8")
public class ${table.controllerName} {

    @Autowired
    private ${table.serviceName} ${(table.serviceName)?uncap_first};

    @ApiOperation(value = "查询单条数据", notes = "查询单条数据")
    @GetMapping("findOne")
    public JSONObject findOne(${entity} ${entity?uncap_first}) {
        return ${(table.serviceName)?uncap_first}.findOne(${entity?uncap_first});
    }


    @ApiOperation(value = "查询列表数据", notes = "查询列表数据")
    @GetMapping("findList")
    public JSONObject findList(${entity} ${entity?uncap_first}) {
        return ${(table.serviceName)?uncap_first}.findList(${entity?uncap_first});
    }
    
    
    @ApiOperation(value = "查询分页列表数据", notes = "查询分页列表数据")
    @GetMapping("findPageList")
    public JSONObject findPageList(${entity} ${entity?uncap_first},
                                        @Valid @NotNull(message = "页码为空") long page,
                                        @Valid @NotNull(message = "分页行数为空") long pageSize) {
        return ${(table.serviceName)?uncap_first}.findPageList(${entity?uncap_first}, page, pageSize);
    }
    
    
    @ApiOperation(value = "新增", notes = "新增")
    @PostMapping("add")
    public JSONObject add(@RequestBody @Valid ${entity} ${entity?uncap_first}) {
        return ${(table.serviceName)?uncap_first}.add(${entity?uncap_first});
    }
    
    
    @ApiOperation(value = "修改", notes = "修改")
    @PostMapping("update")
    public JSONObject update(@RequestBody @Valid ${entity} ${entity?uncap_first}) {
        return ${(table.serviceName)?uncap_first}.update(${entity?uncap_first});
    }

    @ApiOperation(value = "删除", notes = "删除")
    @PostMapping("delete")
    public JSONObject delete(@RequestBody ${entity} ${entity?uncap_first}) {
        return ${(table.serviceName)?uncap_first}.delete(${entity?uncap_first});
    }
    


}